<?php


class Sherpa_Hook_FreeCupArticle
{

    /**
     * Hook-Key: Sherpa/View/Cart/Index/ProductsSubtotal
     *
     * @param WSB_Xtension_View $view
     * @return string
     */
    public function viewCartIndexProductsSubtotal(WSB_Xtension_View $view)
    {
    	$subtotal = $view->products->calculateTotal($view->coupon) - 8.5;
        if($subtotal > 200) {
    		return '<tr class="bsk-details-total">
    			<td colspan="3" class="label">
    				PALNU Thermo-Trinkbecher im Wert von CHF 14.90
    			</td>
    			<td class="price">
    				gratis
    			</td>
    		</tr>';
        }
    }

    /**
     * Hook-Key: Sherpa/View/Checkout/Summary/Subtotal
     *
     * @param WSB_Xtension_View $view
     * @return string
     */
    public function viewCheckoutSummarySubtotal(WSB_Xtension_View $view)
    {
    	$subtotal = $view->products->calculateTotal($view->coupon) - 8.5;
        if($subtotal > 200) {
    		return '<tr class="bsk-details-total">
    			<td colspan="3" class="label">
    				PALNU Thermo-Trinkbecher im Wert von CHF 14.90
    			</td>
    			<td class="price">
    				gratis
    			</td>
    		</tr>';
        }
    }

    /**
     * Hook-Key: Sherpa/View/Checkout/Confirmation/Subtotal
     *
     * @param WSB_Xtension_View $view
     * @return string
     */
    public function viewCheckoutConfirmationSubtotal(WSB_Xtension_View $view)
    {
    	$subtotal = $view->products->calculateTotal($view->coupon) - 8.5;
        if($subtotal > 200) {
    		return '<tr class="bsk-details-total">
    			<td colspan="3" class="label">
    				PALNU Thermo-Trinkbecher im Wert von CHF 14.90
    			</td>
    			<td class="price">
    				gratis
    			</td>
    		</tr>';
        }
    }

    /**
     * Hook-Key: Sherpa/View/Checkout/Mail/Subtotal
     *
     * @param WSB_Xtension_View $view
     * @return string
     */
    public function viewCheckoutMailSubtotal(WSB_Xtension_View $view)
    {
    	$subtotal = $view->products->calculateTotal($view->coupon) - 8.5;
        if($subtotal > 200) {
            $str = '= GRATIS: PALNU Thermo-Trinkbecher im Wert von CHF 14.90' . PHP_EOL;
            return utf8_encode(html_entity_decode($str));
        }
    }

}
